//
//  ViewController.swift
//  YMPhotosDemo
//
//  Created by youmy on 2019/12/17.
//  Copyright © 2019 youmy. All rights reserved.
//

import UIKit
import Photos

class ViewController: UIViewController {
    @IBOutlet weak var albumImage: UIImageView!
    
    /// 带缓存的图片管理对象
    var imageManager: PHCachingImageManager!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // 初始化和重置缓存
        self.imageManager = PHCachingImageManager()
        self.resetCachedAssets()
    }
    
    //重置缓存
    func resetCachedAssets(){
        self.imageManager.stopCachingImagesForAllAssets()
    }
    

    @IBAction func toAlbumAction(_ sender: UIButton) {
        performSegue(withIdentifier: "toalbum", sender: nil)
    }
    
    
    @IBAction func backSegue(segue: UIStoryboardSegue){
        if segue.identifier == "passValue" {
            let backVc = segue.source as! YMAlbumViewController
            imageManager.requestImage(for: backVc.selAsset, targetSize: CGSize(width: 600, height: 600), contentMode: .aspectFill, options: nil, resultHandler: {[weak self] (image, info) in
                DispatchQueue.main.async {
                    self?.albumImage.image = image
                }
            })
        }
    }
}

